/**
 * @description 定义通用的状态管理器对象
 */
import {enCodeApi,deCodeApi} from '@/utils'
import _ from 'lodash'
const stateInit = {
        token:'',
        userInfo:{},
        menuList:[],
        userRights:{}
}
const common ={
    namespaced:true,
    state : _.cloneDeep(stateInit),
    getters:{
        token(_state){
            return !!_state.token ? deCodeApi(_state.token) : ''
        },
        userInfo: _state=>_state.userInfo,
        menuList: _state=>_state.menuList,
        userRights:_state=>_state.userRights
    },
    mutations:{
        setToken(_state,_token){
            _state.token = enCodeApi(_token)
        },
        setUserInfo(_state, _userInfo){
            _state.userInfo=_userInfo
        },
        setMenuList(_state,_menuList){
            _state.menuList=_menuList
        },
        setUserRights(_state,_userRights){
            _state.userRights=_userRights
        },
        clear(_state) {
            _state = _.cloneDeep(stateInit)
        }
    }
}
export default common